var _path = $('#path').val();//获取路径/frontend/web/ajax/
var _token = $('meta[name="csrf-token"]').attr("content");//获取csrf 因为ajax POST提交需要
$(function() {
    $(".btnQuery").click(function() {
        if ($("#lendinvestmentsearch-start_querenshutime").val() == "" &&
                $("#lendinvestmentsearch-start_qixidate").val() == "" &&
                $("#lendinvestmentsearch-start_generatedrightdate").val() == "" &&
                $("#lendinvestmentsearch-start_expiredate").val() == ""
                ) {
            alert("亲，请选择查询日期组合！");
            return false;
        }
        if ($("#lendinvestmentsearch-start_querenshutime").val() != '' && ($("#lendinvestmentsearch-end_querenshutime").val() == '')) {

            alert("亲,请选择结束进账日期!");
            return false;
        }
        if ($("#lendinvestmentsearch-start_qixidate").val() != '' && $("#lendinvestmentsearch-end_qixidate").val() == '') {
            alert("亲,请选择结束起息日期!");
            return false;
        }
//
        if ($("#lendinvestmentsearch-start_generatedrightdate").val() != "" && $("#lendinvestmentsearch-end_generatedrightdate").val() == "") {
            alert("亲,请选择结束匹配日期!");
            return false;
        }
        if ($("#lendinvestmentsearch-start_expiredate").val() != "" && $("#lendinvestmentsearch-end_expiredate").val() == "") {
            alert("亲,请选择结束到期日期!");
            return false;
        }

//开始
        if ($("#lendinvestmentsearch-start_querenshutime").val() == '' && ($("#lendinvestmentsearch-end_querenshutime").val() != '')) {

            alert("亲,请选择开始进账日期!");
            return false;
        }
        if ($("#lendinvestmentsearch-start_qixidate").val() == '' && $("#lendinvestmentsearch-end_qixidate").val() != '') {
            alert("亲,请选择开始起息日期!");
            return false;
        }
//
        if ($("#lendinvestmentsearch-start_generatedrightdate").val() == "" && $("#lendinvestmentsearch-end_generatedrightdate").val() != "") {
            alert("亲,请选择开始匹配日期!");
            return false;
        }
        if ($("#lendinvestmentsearch-start_expiredate").val() == "" && $("#lendinvestmentsearch-end_expiredate").val() != "") {
            alert("亲,请选择开始到期日期!");
            return false;
        }


    });
    //ajax提交 获取数据
    var search_count = $('#search_count').val();
    if (search_count > 0) {//判断查询条件数据大于0，才可以发送
        $("#sendbtn").click(function() {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: "/lenders/lendinvestment/send-inters",
                data: {
                    _csrf: _token,
//                    start_generatedrightdate: $("#lendinvestmentsearch-start_generatedrightdate").val(),
//                    end_generatedrightdate: $("#lendinvestmentsearch-end_generatedrightdate").val(),
//                    start_querenshutime: $("#lendinvestmentsearch-start_querenshutime").val(),
//                    end_querenshutime: $("#lendinvestmentsearch-end_querenshutime").val(),
//                    start_qixidate: $("#lendinvestmentsearch-start_qixidate").val(),
//                    end_qixidate: $("#lendinvestmentsearch-end_qixidate").val(),
//                    start_expiredate: $("#lendinvestmentsearch-start_expiredate").val(),
//                    end_expiredate: $("#lendinvestmentsearch-end_expiredate").val(),
                },
                success: function(data) {
                    if (data.status === 'success') {
                        alert(data.message);
                    } else {
                        alert(data.message);
                    }
                }
            });
        });
    } else {
        return false;
    }
})
//赋值给手机号码
//如果先添加内容，要获取出来，传入查询条件，在返回给页面
//如果先添加内容，要获取出来，传入查询条件，在返回给页面
//        $('#btnQuery').click(function(){
//             $('#smssearch-lender_body').val(window.parent.$('#sms-body').val());
//        });
//        console.log($("#sms-body").val())

//查询
//         $('#btnQuery').click(function(){
var search_sms = $('#search_sms').val();//获取手机号码
var search_body = $('#search_body').val();//获取短信条数
if(search_body=='undefined'){
    search_body = 0;
}
window.parent.$('#lender_count').text('共' + search_body + '条');//赋值给短信条数
window.parent.$('#sms-phones').val(search_sms);//赋值给手机号码
window.parent.$('#lender_href').html('<a  target=_blank href=' + search_sms + '>手机号访问地址链接</a>');//赋值给手机号码


//1等于理财客户，2,等于借款客户
$("#smssearch-smstype").click(function() {
    getkehu()
});
getkehu();
//判断理财客户 aor 借款客户
function  getkehu() {
    var _smstype = $('#smssearch-smstype').val();
    if (_smstype == '1') {//理财客户
//         var url = document.location.toString();
//        window.location.href=url;
        $('.lender_companyname').show();
        $('.lender_customerManagerName').show();
        $('.lender_username').show();
        $('.lender_idtype').show();
        $('.borrower_username').hide();
        //
    } else if (_smstype == '2') {//借款客户
//        var url = document.location.toString();
//         console.log(url+"?SmsSearch%5BsmsType%5D=2");
//         window.location.href=url+"?SmsSearch%5BsmsType%5D=2";
        $('.lender_companyname').hide();
        $('.lender_idtype').hide();
        $('.lender_customerManagerName').hide();
        $('.lender_username').hide();
        $('.borrower_username').show();
    }
}
       